package com.blue.core.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * Spring工具类，用来快速获取对象
 * 
 * @author zhengj
 * @since 1.0 2017年2月7日
 */
@Component
public class SpringUtil implements ApplicationContextAware
{
	private static ApplicationContext ctx;
	
	public SpringUtil()
	{
	}
	
	public static <T> T getBean(String name, Class<T> clazz)
	{
		return ctx.getBean(name, clazz);
	}
	
	public static <T> T getBean(Class<T> clazz)
	{
		return ctx.getBean(clazz);
	}

	@Override
	public void setApplicationContext(ApplicationContext ctx) throws BeansException
	{
		SpringUtil.ctx = ctx;
	}
	
}
